<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // ^ -> 以什么开头
    // $ -> 以什么结尾
    const message = 'my name is why'
    // 字符串方法
    if (message.startsWith('my')) console.log('以 my 开头')
    if (message.endsWith('why')) console.log('以 why 结尾')
    // 正则
    if (/^my/ig.test(message)) console.log('以 my 开头')
    if (/why$/ig.test(message)) console.log('以 why 结尾')

    console.log(/^coder$/.test("codaaaer")) // false

  </script>
</body>

</html>